<%--
  ** Copyright(c) 2005 BroadVision, Inc. All rights reserved.
  **
  ** This software is copyrighted.  Under the copyright laws, this software
  ** may not be copied, in whole or in part, without prior written consent
  ** of BroadVision, Inc. or its assignees. This software is provided under
  ** the terms of a license between BroadVision and the recipient, and its
  ** use is subject to the terms of that license.
  **
  ** This software may be protected by one or more U.S. and International
  ** patents. Certain applications of BroadVision One-To-One software are
  ** covered by U.S. patent 5,710,887.
  **
  ** TRADEMARKS: BroadVision and the BroadVision logo are registered
  ** trademarks, and BroadVision One-To-One is a trademark of BroadVision,
  ** Inc. IONA and Orbix are trademarks of IONA Technologies, Ltd. RSA,
  ** MD5, and RC2 are trademarks of RSA Data Security, Inc. All other
  ** trademarks, service marks, and trade names belong to their respective
  ** owners. BroadVision, Inc. disclaims any proprietary interest in the
  ** marks and names of others.
  --%>

<%@ page import="java.util.HashMap" %>
<%@ page import="java.util.HashSet" %>

<%@ page import="org.apache.struts.Globals" %>
<%@ page import="org.apache.struts.action.ActionMapping" %>

<%@ page import="com.broadvision.report.admin.ReportConfig" %>
<%@ page import="com.broadvision.report.admin.ProcessConfig" %>

<%@ taglib uri="/WEB-INF/c.tld" prefix="c" %>
<%@ taglib uri="/WEB-INF/struts-html-el.tld" prefix="html-el" %>
<%@ taglib uri="/WEB-INF/struts-bean-el.tld" prefix="bean-el" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>

<%
  final String ctxPath = request.getContextPath();
  final ActionMapping mapping =
                      (ActionMapping)request.getAttribute(Globals.MAPPING_KEY);
  pageContext.setAttribute("reqPath", mapping.getPath() + ".do");

  pageContext.setAttribute("purpose", request.getAttribute("selectPurpose"));

  final String trClassList[] = { "listEven", "listOdd" };
  pageContext.setAttribute("listFlipFlop", trClassList);

  final ReportConfig model =
          (ReportConfig)request.getAttribute("runtimeReportConfigModel");
%>

<script language="JavaScript">
  function gotoCat(oid) {
    document.processBrowseForm.currentCategoryOid.value = oid;
    document.processBrowseForm.action = '<c:url value="${reqPath}"/>';
    document.processBrowseForm.submit();
  }
  function addProc(url)
  {
    var msg = '<bean-el:message key="bp.report.process.confirm.add" bundle="bp.messages"/>';

    if (!confirm(msg))
      return false;

    location.replace(url);
    return true;
  }
</script>

<%
  final HashMap map = new java.util.HashMap();
  final String catOid = request.getParameter("currentCategoryOid");
  if (catOid != null && catOid.length() > 0) {
    map.put("currentCategoryOid", catOid);
  }
  else {
    map.put("currentCategoryOid", "0");
  }
  pageContext.setAttribute("pagetabParam", map, PageContext.PAGE_SCOPE);
%>

<c:set var="rootName"><bean-el:message key="bp.process.processBrowse.rootCategory" bundle="bp.messages"/></c:set>

<html-el:form action="${reqPath}">
  <html-el:hidden name="processBrowseForm" property="currentCategoryOid"/>
  <input type="hidden" name="subcategoryOid"/>
  <input type="hidden" name="destinedCategoryOid"/>
  <input type="hidden" name="processOid"/>
  <input type="hidden" name="categoryName"/>
  <input type="hidden" name="oneOnly"/>
  <input type="hidden" name="setOnlineStatus"/>
  <input type="hidden" name="forwardAction"/>
  <table class="zoneFive" width="100%" border="0"
         cellspacing="0" cellpadding="0" summary="content area">
    <tr>
      <td valign="top" width="100%">
        <div class="pageTitle">
          <bean-el:message
            key="bp.report.process.select.title.${purpose}" bundle="bp.messages"
          />
        </div>
        <div class="errorMessage"><html-el:errors bundle="bp.messages"/></div>
        <div><%@include file="/mc/common/pagetab.jsp" %></div>
        <div class="breadcrumb">
          <c:if test="${processBrowseView.map.viewCategory =='true'}">
            <c:if test="${empty processBrowseView.map.paths}">
              <c:out value="${rootName}"/>
              <c:set var="catName" value="${rootName}"/>
            </c:if>
            <c:if test="${!empty processBrowseView.map.paths}">
              <html-el:link page="${reqPath}">
                <c:out value="${rootName}"/>
              </html-el:link>
              <c:forEach var="path" items="${processBrowseView.map.paths}">
                <c:set var="catName"><c:out value="${path.map.name}"/></c:set>
                &nbsp;
                <bean-el:message
                  key="bp.process.pathSeparator" bundle="bp.messages"
                />
                &nbsp;
                <c:if test="${path.map.isCurrentPath == 'false'}">
                  <a href='#'
                    onclick="gotoCat('<c:out value="${path.map.oid}"/>');">
                    <c:out value="${path.map.name}"/>
                  </a>
                </c:if>
                <c:if test="${path.map.isCurrentPath == 'true'}">
                  <c:out value="${path.map.name}"/>
                </c:if>
              </c:forEach>
            </c:if>
          </c:if>
        </div>

        <div class="pageSubtitle">
          <span class="left">
            <bean-el:message
              key="bp.process.processBrowse.subcategories"
              bundle="bp.messages"
            />
          </span>
          <span class="right">&nbsp;</span>
        </div>

        <table class="dataTable" border="0" cellspacing="1" cellpadding="2"
               summary="Category" width="100%">
          <tr class="listHeader">
            <th id="SubCategoryName" align="left" width="80%">
              <bean-el:message
                key="bp.process.processBrowse.header.subcategoryName"
                bundle="bp.messages"
              />
            </th>
          </tr>
          <c:if test="${empty processBrowseView.map.subcategories}">
            <tr class="listEven">
              <td align="center">
                <bean-el:message
                  key="bp.process.processBrowse.noSubcategories"
                  bundle="bp.messages"
                />
              </td>
            </tr>
          </c:if>
          <c:if test="${!empty processBrowseView.map.subcategories}">
            <c:forEach var="subcat"
                       items="${processBrowseView.map.subcategories}"
                       varStatus="index">
              <tr class="<c:out value="${listFlipFlop[(index.count+1)%2]}"/>">
                <td headers="SubCategoryName">
                  <a href='#'
                    onclick="gotoCat('<c:out value="${subcat.map.oid}"/>');">
                    <c:out value="${subcat.map.name}"/>
                  </a>
                </td>
              </tr>
            </c:forEach>
          </c:if>
        </table>
        <br>
        <c:if test="${!empty processBrowseView.map.paths}">
          <div class="pageSubtitle">
            <span class="left">
              <bean-el:message
                key="bp.process.processBrowse.processesInSubcategory"
                arg0="${catName}"
                bundle="bp.messages"
              />
            </span>
            <span class="right">&nbsp;</span>
          </div>
          <table class="dataTable" border="0" cellspacing="1" cellpadding="2"
                 summary="Notification table" width="100%">
            <tr class="listHeader">
              <th id="Model" align="left">
                <bean-el:message
                  key="header.processModel" bundle="bp.messages"
                />
              </th>
              <th id="Package" align="left">
                <bean-el:message
                  key="header.processPackage" bundle="bp.messages"
                />
              </th>
              <th id="LastModifiedDate" align="left">
                <bean-el:message
                  key="header.lastModifiedDate"
                  bundle="bp.messages"
                />
              </th>
            </tr>
            <c:if test="${empty processBrowseView.map.processes}">
              <tr class="listEven">
                <td align="center" colspan="3">
                  <bean-el:message
                    key="bp.process.noProcess" bundle="bp.messages"
                  />
                </td>
              </tr>
            </c:if>
            <c:if test="${!empty processBrowseView.map.processes}">
              <%
              final ProcessConfig procList[] = model.getProcessList();
              final HashSet oidSet = new HashSet(procList.length);
              int i;
              for (i = 0; i < procList.length; ++i)
                oidSet.add(new Long(procList[i].getOid()));
              %>
              <c:forEach var="process"
                         items="${processBrowseView.map.processes}"
                         varStatus="index">
                <tr class="<c:out value="${listFlipFlop[(index.count+1)%2]}"/>">
                  <td headers="Model">
                    <c:set var="procUrl" value=""/>
                    <c:choose>
                      <c:when test="${purpose == 'add'}">
                        <c:set var="procOid" value="${process.map.oid}"/>
                        <%
                        final Long procOid =
                                    (Long)pageContext.getAttribute("procOid");
                        if (!oidSet.contains(procOid)) {
                        %>
                          <c:url var="procUrl" value="/bp/reportProcessAdd.do">
                            <c:param name="procOid" value="${procOid}"/>
                          </c:url>
                          <a href="#"
                             onclick="addProc('<c:out value="${procUrl}"/>');">
                            <c:out value="${process.map.name}"/>
                          </a>
                        <%
                        }
                        %>
                      </c:when>
                    </c:choose>

                    <c:if test="${empty procUrl}">
                      <c:out value="${process.map.name}"/>
                    </c:if>
                  </td>
                  <td headers="Package">
                    <c:out value="${process.map.packageName}"/>
                  </td>
                  <td headers="LastModifiedDate">
                    <bean:write
                      name="process"
                      property="lastModifiedDate"
                      formatKey="format.datetime.long"
                      bundle="mc.messages"
                    />
                  </td>
                </tr>
              </c:forEach>
            </c:if>
          </table>
        </c:if>
      </td>
    </tr>
  </table>
</html-el:form>

<!-- =============================================================
  ** vim: set ts=2 expandtab syntax=jsp:
  -->
